package com.ts.api.http.feedback;

import com.alibaba.fastjson.JSONObject;
import com.gitee.apanlh.util.base.Eq;
import com.gitee.apanlh.util.log.LogLevel;
import com.gitee.apanlh.util.net.http.HttpClientBuilder;
import com.gitee.apanlh.util.net.http.HttpResponse;
import com.gitee.apanlh.util.valid.ValidParam;
import com.gitee.apanlh.web.http.HttpMethod;
import com.gitee.apanlh.web.model.vo.RequestVO;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * 快手
 *
 * https://docs.qingque.cn/d/home/eZQDnexll3-ebbtlX3xEDvBN3?identityId=1zy0We0ri6t
 *
 * @author caoxin
 */
@Component
public class KuaiShouFeedbackHandler implements FeedbackHandler {

    @Override
    public boolean match(RequestVO requestVO) {
        return Eq.str(requestVO.getStr("type"), "kuaishou");
    }

    private static final String CALLBACK_URL = "http://ad.partner.gifshow.com/track/activate?event_type=__EVENT_TYPE__&event_time=__EVENT_TIME__&callback=__CALLBACK__";

    @Override
    public Object feedback(RequestVO requestVO) {
        String callback = requestVO.getStr("callback");
        if (ValidParam.isNotEmpty(callback)) {
            String eventType = "9";
            String eventTime = String.valueOf(System.currentTimeMillis());
            String url = CALLBACK_URL.replace("__EVENT_TYPE__", eventType).replace("__EVENT_TIME__", eventTime).replace("__CALLBACK__", callback);
            HttpResponse build = HttpClientBuilder.builder(url, HttpMethod.GET)
                    .withLogLevel(LogLevel.WARN)
                    .withErrorLogLevel(LogLevel.WARN)
                    .build();
            String str = build.getStr();
            JSONObject jsonObject = JSONObject.parseObject(str);
        }
        return new HashMap<>();
    }

}
